// pages/curriculum/curriculum.js
const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    courses:[],
    colorArrays: [ "#85B8CF", "#90C652", "#D8AA5A", "#FC9F9D", "#0A9A84", "#61BC69", "#12AEF3", "#E29AAD"],
    curWeek:17


  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
   this.getCourse();

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
    
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },

  getCourse:function(){
    var sid=app.globalData.sid;
    // var sid=1743205000113;
    var curWeek=this.data.curWeek
    var that=this
    wx.request({
      url: 'https://smart.songblog.top/getCourse',
      data: {sid,curWeek},
      header: {'content-type':'application/json'},
      method: 'GET',
      dataType: 'json',
      responseType: 'text',
      success: (result) => {
        console.log(result);
        that.setData({
          courses:result.data,
        })

      },
      fail: () => {},
      complete: () => {}
    });

  },


  subWeek:function(){

    this.setData({
      curWeek:this.data.curWeek-1
    })
    var sid=app.globalData.sid;
    // var sid=1743205000113;
    var curWeek=this.data.curWeek
    var that=this
    wx.request({
      url: 'https://smart.songblog.top/getCourse',
      data: {sid,curWeek},
      header: {'content-type':'application/json'},
      method: 'GET',
      dataType: 'json',
      responseType: 'text',
      success: (result) => {
        console.log(result);
        that.setData({
          courses:result.data,
        })

      },
      fail: () => {},
      complete: () => {}
    });
  },

  addWeek:function(){

    this.setData({
      curWeek:this.data.curWeek+1
    })
    var sid=app.globalData.sid;
    // var sid=1743205000113;
    var curWeek=this.data.curWeek
    var that=this
    wx.request({
      url: 'https://smart.songblog.top/getCourse',
      data: {sid,curWeek},
      header: {'content-type':'application/json'},
      method: 'GET',
      dataType: 'json',
      responseType: 'text',
      success: (result) => {
        console.log(result);
        that.setData({
          courses:result.data,
        })

      },
      fail: () => {},
      complete: () => {}
    });
  }

})